import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

public class inputParameters extends JFrame{
	
	public static void main(String args[]){
		inputParameters input = new inputParameters();
		input.setSize(225,325);
		input.setVisible(true);
	}
	
	private JTextField maxProds;
	public inputParameters() {
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		getContentPane().setLayout(null);
		
		JLabel lblMaximumProducts = new JLabel("Max Products:");
		lblMaximumProducts.setBounds(10, 11, 91, 14);
		getContentPane().add(lblMaximumProducts);
		
		maxProds = new JTextField();
		maxProds.setBounds(106, 8, 86, 20);
		getContentPane().add(maxProds);
		maxProds.setColumns(10);
		
		JLabel lblProducers = new JLabel("Producers:");
		lblProducers.setBounds(10, 36, 86, 14);
		getContentPane().add(lblProducers);
		
		JLabel lblConsumers = new JLabel("Consumers:");
		lblConsumers.setBounds(106, 36, 86, 14);
		getContentPane().add(lblConsumers);
		
		final JTextArea producerArea = new JTextArea();
		producerArea.setBounds(10, 61, 91, 179);
		getContentPane().add(producerArea);
		
		JScrollPane producerScroll = new JScrollPane(producerArea);
		producerScroll.setBounds(producerArea.getBounds());
		getContentPane().add(producerScroll);
		
		final JTextArea consumerArea = new JTextArea();
		consumerArea.setBounds(106, 61, 91, 179);
		getContentPane().add(consumerArea);
		
		JScrollPane consumerScroll = new JScrollPane(consumerArea);
		consumerScroll.setBounds(consumerArea.getBounds());
		getContentPane().add(consumerScroll);
		
		JButton goButton = new JButton("Go!");
		goButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int maxProducts = Integer.parseInt(maxProds.getText());
				List<Integer> producerWaitTimes = new ArrayList<Integer>();
				List<Integer> consumerWaitTimes = new ArrayList<Integer>();
			
				Scanner scan = new Scanner(producerArea.getText().replaceAll(" ", "").trim());
				while(scan.hasNext()){
					producerWaitTimes.add(scan.nextInt());
				}
				
				scan = new Scanner(consumerArea.getText().replaceAll(" ", "").trim());
				while(scan.hasNext()){
					consumerWaitTimes.add(scan.nextInt());
				}
				
				simulator sim = new simulator(maxProducts, producerWaitTimes, consumerWaitTimes);
			}
		});
		
		goButton.setBounds(10, 250, 182, 23);
		getContentPane().add(goButton);
	}
}
